layui.use(['jquery','layer'], function(){
	var $ = layui.jquery,layer = layui.layer;
	var $hash = window.location.hash;
	if($hash){
		$hash = $hash.substr(1);
		$hash != '' ? open($hash) : window.location.href = 'index.html';
	}else{
		window.location.href = 'index.html';
	}
	function open(name){
		$('#word span').text(decodeURI(name));
		createScript(name);
	}
	function createScript(name){
  		var script = document.createElement('script');
  		script.src = 'https://s.video.qq.com/smartbox?callback=searchFun&plat=2&ver=0&num=10&otype=json&query='+ name +'&uid=acc74aac-9a3e-46ee-b29b-f265ef5bd98a&_=1558090848806'
  		document.body.appendChild(script);
  		function onScriptLoad(e){
  			document.body.removeChild(script);
  		}
  		if(script.attachEvent && !(script.attachEvent.toString && script.attachEvent.toString().indexOf('[native code') < 0)){
	        script.attachEvent('onreadystatechange', function(e){
	          onScriptLoad(e);
	        });
	      } else {
	        script.addEventListener('load', function(e){
	          onScriptLoad(e);
	        }, false);
	      }
	}
	window.icoClick = function icoClick(target){
		var a = $(target).prev();
		var node = document.createElement('a');
		node.href = a[0].href;
		node.target = a[0].target;
		node.click();
	}
	function appendBodyLi(appendLi){
		var ul = [];
		for (var i = 0; i < appendLi.length; i++) {
			var item = appendLi[i];
			var li = ['<li class="fed-list-item fed-padding fed-col-xs4 fed-col-sm3 fed-col-md2">','<a class="fed-list-pics fed-lazy fed-part-2by3" style="display: block; background-image: url(\'',item.dc,'\');" href="play.html#https://v.qq.com/x/cover/'
			,item.id,
			'.html" target="_blank">',
			,'</a><div class="ico_play" onclick="icoClick(this)"></div>',
			'<a class="fed-list-title fed-font-xiv fed-text-center fed-text-sm-left fed-visible fed-part-eone" href="play.html#https://v.qq.com/x/cover/',item.id,'.html">',item.title,'</a>',
			'<span class="fed-list-desc fed-font-xii fed-visible fed-part-eone fed-text-muted fed-hide-xs fed-show-sm-block">',item.pa,'</span>',
			'</li>'
			].join('');
			ul.push(li);
		}
		var film = $('#film');
  		film.empty();
  		film.append(ul.join(''));
		return ;
	}
	window.searchFun = function searchFun(res){
		var result = res.result;
  		if(result.code === 0){
  			var items = res.item;
  			var appendLi = [];
  			for (var i = 0; i < items.length; i++) {
  				var item = items[i];
  				if(item.url && item.tt && item.dc){
  					appendLi.push(item)
  				}
  			}
  			appendBodyLi(appendLi);
  		}
	}
});